package msu.ml.data;

import msu.ml.core.*;
import msu.ml.core.NxInstances;
import weka.filters.*;

/**
 * This class serves as an adapter allowing the Remove filter in Weka to be used
 * inside the Nexrad Explorer Software.
 *
 * @author Reginald M Mead
 * @version 1.0
 * @see IDataPreProcessor
 */
public class AttributeRemovalPreProcessor 
extends weka.filters.unsupervised.attribute.Remove implements IDataPreProcessor 
{
    /**
     * Create a new Attribute Removal Preprocessor
     */
    public AttributeRemovalPreProcessor()
    {

    }

    private boolean enabled = true;
    public boolean getEnabled(){return enabled;}
    public void setEnabled(boolean value){this.enabled = value;}

    /**
     * Processes data by removing or keeping the specified attributes
     * @param data data to process
     * @return processed data
     */
    public NxInstances process(NxInstances data)
    {
        if(enabled)
        {
            try
            {
                this.setInputFormat(data);
                NxInstances result = new NxInstances(Filter.useFilter(data, this));
                result.setSourceFile(data.getSourceFile());
                return result;
            }
            catch(Exception e)
            {
                System.out.println(e);
                return null;
            }
        }
        return data;
    }

    public String toString()
    {
        return "<attribute_removal_pre_processor invert=\"" + 
            this.getInvertSelection() + "\" indices=\"" + 
            this.getAttributeIndices() + "\" />";
    }

}
